#!/usr/bin/env python
#
'''
Created on 2009-4-11

@author: Wang_Yuan
'''

import os.path
from ConfigParser import *

SETTING_FILE = os.path.realpath(os.path.expanduser('~/.IntelligentVocabulary'))

cp = ConfigParser()

if os.path.exists(SETTING_FILE):
    try:
        cp.readfp(open(SETTING_FILE))
    except:
        pass

def getRecentList():
    SECTION = 'recent'
    OPTION = 'recent_open'
    if cp.has_section(SECTION) and cp.has_option(SECTION, OPTION):
        recentString = cp.get(SECTION, OPTION)
        recent = recentString.split(',')
        return recent
    else:
        return []
    
def saveRecentList(recent):
    SECTION = 'recent'
    OPTION = 'recent_open'
    
    recentString = ','.join(recent)
    if not cp.has_section(SECTION):
        cp.add_section(SECTION)
    cp.set(SECTION, OPTION, recentString)
    cp.write(open(SETTING_FILE, 'wb'))
    
def isSoundEnable():
    SECTION = 'sound'
    OPTION = 'enabled'
    return cp.has_section(SECTION) and cp.has_option(SECTION, OPTION) and cp.getboolean(SECTION, OPTION)

def getURL():
    SECTION = 'sound'
    OPTION = 'url'
    if cp.has_section(SECTION) and cp.has_option(SECTION, OPTION):
        return cp.get(SECTION, OPTION)
    else:
        return 'http://www.howjsay.com/mp3/:word:.mp3'
    
def getCachePath():
    SECTION = 'sound'
    OPTION = 'cache-path'
    if cp.has_section(SECTION) and cp.has_option(SECTION, OPTION):
        print cp.get(SECTION, OPTION)
        return os.path.realpath(os.path.expanduser(cp.get(SECTION, OPTION)))
    else:
        return '~/.iv_cache'

def getExt():
    SECTION = 'sound'
    OPTION = 'ext'
    if cp.has_section(SECTION) and cp.has_option(SECTION, OPTION):
        return cp.get(SECTION, OPTION)
    else:
        return '.mp3'
    